home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 21
/
Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso
/
Aminet
/
dev
/
e
/
Chris_emods.lha
/
progresswin.e
< prev
next >
Wrap
Text File
|
1997-08-26
|
6KB
|
211 lines
OPT MODULE, PREPROCESS, REG = 5
MODULE '*screens'
MODULE 'intuition/intuition'
MODULE 'intuition/screens'
MODULE 'utility/tagitem'
MODULE 'gadtools'
MODULE 'libraries/gadtools'
MODULE 'graphics/rastport'
MODULE 'graphics/gfxmacros'
MODULE 'graphics/text'
MODULE 'diskfont'
EXPORT OBJECT progresswin PRIVATE
win:PTR TO window
rp:PTR TO rastport
scr:PTR TO screen
dri:PTR TO drawinfo
vis
tf:PTR TO textfont
wrmsk
windowdim[4]:ARRAY OF INT
progressgaddim:PTR TO LONG
currpercent:INT
ENDOBJECT
PROC lockprogressscreen(pw:PTR TO progresswin, screenname) HANDLE
pw.scr := LockPubScreen(screenname)
IF pw.scr = NIL THEN Throw("PUBS", screenname)
pw.dri := GetScreenDrawInfo(pw.scr)
IF pw.dri = NIL THEN Raise("DRI")
pw.vis := GetVisualInfoA(pw.scr, NIL)
IF pw.vis = NIL THEN Raise("VIS")
EXCEPT
unlockprogressscreen(pw)
ENDPROC
PROC unlockprogressscreen(pw:PTR TO progresswin)
IF pw.vis THEN FreeVisualInfo(pw.vis)
IF pw.dri THEN FreeScreenDrawInfo(pw.scr, pw.dri)
IF pw.scr THEN UnlockPubScreen(NIL, pw.scr)
ENDPROC
EXPORT PROC openprogresswin(pw:PTR TO progresswin, scrname, win2ptr:PTR TO window, progressstr) HANDLE
DEF winptr = NIL:PTR TO window
IF findpubscreen(scrname)
lockprogressscreen(pw, scrname)
ELSE
lockprogressscreen(pw, NIL)
ENDIF
pw.tf := OpenDiskFont([pw.scr.font.name,
pw.scr.font.ysize,
pw.scr.font.style,
FPF_ROMFONT OR FPF_DISKFONT]:textattr)
IF pw.tf = NIL THEN Raise("FONT")
pw.windowdim[2] := 250
pw.windowdim[3] := pw.tf.ysize * 6
IF win2ptr
pw.windowdim[0] := win2ptr.leftedge + (win2ptr.width / 2) - (pw.windowdim[2] / 2)
pw.windowdim[1] := win2ptr.topedge + (win2ptr.height / 2) - (pw.windowdim[3] / 2)
ELSE
pw.windowdim[0] := (pw.scr.width / 2) - (pw.windowdim[2] / 2)
pw.windowdim[1] := (pw.scr.height / 2) - (pw.windowdim[3] / 2)
ENDIF
IF (winptr := OpenWindowTagList(NIL,
[WA_LEFT, pw.windowdim[0],
WA_TOP, pw.windowdim[1],
WA_WIDTH, pw.windowdim[2],
WA_HEIGHT, pw.windowdim[3],
WA_BORDERLESS, TRUE,
WA_AUTOADJUST, TRUE,
TAG_DONE])) = NIL THEN Raise("WIN")
pw.win := winptr
pw.rp := winptr.rport
pw.wrmsk := winptr.rport.mask
SetFont(pw.rp, pw.tf)
SetBPen(pw.rp, pw.dri.pens[BACKGROUNDPEN])
SetDrMd(pw.rp, RP_JAM1)
SafeSetWriteMask(pw.rp, $03)
drawprogresswin(pw)
drawprogresstext(pw, progressstr)
EXCEPT
closeprogresswin(pw)
ENDPROC
EXPORT PROC closeprogresswin(pw:PTR TO progresswin)
IF pw.tf THEN CloseFont(pw.tf)
IF pw.win
pw.rp.mask := pw.wrmsk
CloseWindow(pw.win)
pw.win := NIL
ENDIF
unlockprogressscreen(pw)
ENDPROC
PROC drawprogresswin(pw:PTR TO progresswin)
DEF oldfill
IF pw.win
/* Draw dither fill */
oldfill := pw.rp.areaptrn
SetAPen(pw.rp, pw.dri.pens[SHINEPEN])
SetAfPt(pw.rp, [%1010101010101010, %0101010101010101]:INT, 1)
RectFill(pw.rp, 0, 0, pw.windowdim[2], pw.windowdim[3])
pw.rp.areaptrn := oldfill
/* Draw bevel */
DrawBevelBoxA(pw.rp,
0, 0, pw.windowdim[2], pw.windowdim[3],
[GT_VISUALINFO, pw.vis])
DrawBevelBoxA(pw.rp,
5, 5, pw.windowdim[2] - 10, pw.windowdim[3] - 10,
[GT_VISUALINFO, pw.vis,
GTBB_RECESSED])
/* Fill middle */
SetAPen(pw.rp, pw.dri.pens[BACKGROUNDPEN])
RectFill(pw.rp, 6, 6, pw.windowdim[2] - 7, pw.windowdim[3] - 7)
/* Gadget */
pw.progressgaddim := [20, pw.windowdim[3] / 2,
pw.windowdim[2] - 40, pw.tf.ysize + 6]
DrawBevelBoxA(pw.rp,
pw.progressgaddim[0], pw.progressgaddim[1],
pw.progressgaddim[2], pw.progressgaddim[3],
[GT_VISUALINFO, pw.vis,
GTBB_RECESSED])
ENDIF
ENDPROC
EXPORT PROC drawprogresstext(pw:PTR TO progresswin, string)
DEF textext:textextent, fit
/* Text */
SetAPen(pw.rp, pw.dri.pens[BACKGROUNDPEN])
RectFill(pw.rp, 10, (pw.windowdim[3] / 3) - pw.tf.baseline,
pw.windowdim[2] - 11, (pw.windowdim[3] / 3) - pw.tf.baseline + pw.tf.ysize)
SetAPen(pw.rp, pw.dri.pens[TEXTPEN])
Move(pw.rp, Max(10, (pw.windowdim[2] / 2) - (TextLength(pw.rp, string, StrLen(string)) / 2)), (pw.windowdim[3] / 3) )
IF (fit := TextFit(pw.rp, string,
StrLen(string), textext,
NIL, 1,
pw.windowdim[2] - 11 - pw.rp.cp_x,
pw.scr.font.ysize)) > 0 THEN Text(pw.rp, string, fit)
ENDPROC
EXPORT PROC drawprogressgad(pw:PTR TO progresswin, percentage)
DEF fillpos, percentstr[512]:STRING
DEF textext:textextent, fit
IF pw.win
/* If the percent is the same as before, don't draw anything */
IF (percentage <> pw.currpercent)
pw.currpercent := percentage
fillpos := (((pw.progressgaddim[2] - 5) * percentage) / 100)
/* Draw filled part */
SetAPen(pw.rp, pw.dri.pens[FILLPEN])
RectFill(pw.rp, pw.progressgaddim[0] + 4,
pw.progressgaddim[1] + 2,
pw.progressgaddim[0] + fillpos,
pw.progressgaddim[1] + pw.progressgaddim[3] - 3)
/* Clear empty part */
SetAPen(pw.rp, pw.dri.pens[BACKGROUNDPEN])
RectFill(pw.rp, pw.progressgaddim[0] + 4 + fillpos + 1,
pw.progressgaddim[1] + 2,
pw.progressgaddim[0] + 4 + pw.progressgaddim[2] - 9,
pw.progressgaddim[1] + pw.progressgaddim[3] - 3)
/* Draw percent on the middle of the gadget */
StringF(percentstr, '\d%', percentage)
SetAPen(pw.rp, pw.dri.pens[TEXTPEN])
Move(pw.rp, (pw.windowdim[2] / 2) - (TextLength(pw.rp, percentstr, EstrLen(percentstr)) / 2), pw.progressgaddim[1] + 2 + pw.tf.baseline)
IF (fit := TextFit(pw.rp, percentstr,
EstrLen(percentstr), textext,
NIL, 1,
pw.windowdim[2] - 11 - pw.rp.cp_x,
pw.scr.font.ysize)) > 0 THEN Text(pw.rp, percentstr, fit)
ENDIF
ENDIF
ENDPROC